/*
 * Copyright 2003-2005 (c) Live Media Pty Ltd. <argot@einet.com.au> 
 *
 * This software is licensed under the Argot Public License 
 * which may be found in the file LICENSE distributed 
 * with this software.
 *
 * More information about this license can be found at
 * http://www.einet.com.au/License
 * 
 * The Developer of this software is Live Media Pty Ltd,
 * PO Box 4591, Melbourne 3001, Australia.  The license is subject 
 * to the law of Victoria, Australia, and subject to exclusive 
 * jurisdiction of the Victorian courts.
 */
 
#ifndef CHUNKBUFFER_H_
#define CHUNKBUFFER_H_

#ifdef __cplusplus
extern "C" {
#endif

#define BUFSIZE 508

typedef struct chunk_data
{
	unsigned char buffer[BUFSIZE];
	struct chunk_data * next;
}
chunk_data;


typedef struct chunk_buffer
{
	chunk_data * dataChunks;
	int length;
	int offset;
	bool closed;
	bool gotOutputStream;
	int lastChunkIndex;
	chunk_data * lastUsedChunk;
	chunk_data * lastChunk;	
}
chunk_buffer;

void chunk_buffer_init( chunk_buffer * buffer );

void chunk_buffer_clean( chunk_buffer * buffer );

int chunk_buffer_write_buffer( chunk_buffer * buffer, char * data, int length );

int chunk_buffer_write( chunk_buffer * buffer, int ch );

int chunk_buffer_read( chunk_buffer * buffer );

int chunk_buffer_read_buffer( chunk_buffer * buffer, char * data, int length );

void chunk_buffer_close( chunk_buffer * buffer );

int chunk_buffer_length( chunk_buffer * buffer );

int chunkBufferReader( type_input_stream * in, void * data, char * buffer, int size );
int chunkBufferWriter( type_output_stream * out, void * data, char * buffer, int size );

int chunk_buffer_write_stream( chunk_buffer * buffer, int offset, int length, type_output_stream * out );

#ifdef __cplusplus
} /* end extern "C" */
#endif

#endif /*CHUNKBUFFER_H_*/
